using NUnit.Framework;

namespace NAsserter.Tests
{
    public class AssertThat_Exists : AssertionHelper
    {
        [Test]
        public void with_null_target()
        {
            var choices = new int?[] { 4, 5, 6 };
            AssertThat.Argument((int?)null, "myObj").Exists(choices);
        }

        [Test]
        public void where_one_object_exists_using_params()
        {
            var entity = new TestEntity { Id = 6 };
            AssertThat
                .Argument(entity, "entity")
                .Property(x => x.Id, "Id").Assertions(x => x.Exists(4, 5, 6));
        }

        [Test]
        public void where_one_object_exists_using_array()
        {
            var entity = new TestEntity {Id = 6};
            AssertThat
                .Argument(entity, "entity")
                .Property(x => x.Id, "Id").Assertions(x => x.Exists(new[] { 4, 5, 6 }));
        }

        [Test]
        public void where_one_int_exists()
        {
            AssertThat
                .Argument(5, "age")
                    .Exists(new[] { 4, 5, 6 });
        }

        [Test]
        public void where_two_exists()
        {
            AssertThat.Argument(5, "age").Exists(4, 5, 5, 6 );
        }

        [Test]
        public void where_none_object_exists_with_false_if()
        {
            var entity = new TestEntity { Id = 7 };
            AssertThat
                .Argument(entity, "testComparable")
                .If(x => x.Id != 7)
                    .Property(x => x.Id, "Id").Assertions(x => x.Exists(new[] {4, 5, 6}));
        }

        [Test]
        public void where_none_object_exists_with_true_if()
        {
            var entity = new TestEntity {Id = 7};
            Expect(
                () => AssertThat
                    .Argument(entity, "testComparable")
                        .If(x => x.Id == 7)
                        .Property(x => x.Id, "Id").Assertions(x => x.Exists(new[] { 4, 5, 6 })),
                Throws.TypeOf<NotExistsArgumentException>()
                    .With.Message.Contains("testComparable.Id")
                    .And.Property("ParamName").Contains("testComparable"));
        }

        [Test]
        public void where_none_int_exists()
        {
            Expect(
                () => AssertThat.Argument(3, "age").Exists(new[] { 4, 5, 6 }),
                Throws.TypeOf<NotExistsArgumentException>().With.Property("ParamName").Contains("age"));
        }
    }
}
